{extend name="public:base"}
{block name="body"}
<body class="pear-container">
	<div class="layui-card">
		<div class="layui-card-body">
			<form class="layui-form" action="">
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">会员</label>
                    <div class="layui-input-inline">
                        <input type="text" name="keywords" placeholder="昵称|手机号" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="table-query">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </button>
                    <button type="reset" class="pear-btn pear-btn-md">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
			</form>
		</div>
	</div>
	<div class="layui-card">
		<div class="layui-card-body">
			<table id="table-list" lay-filter="table-list"></table>
		</div>
	</div>
</body>
{/block}
{block name="custome"}
	<script type="text/html" id="table-toolbar">
	</script>
	<script type="text/html" id="table-bar">
        <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="detail" title="查看"><i class="icon pear-icon pear-icon-browse"></i></button>
        <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit" title="编辑"><i class="layui-icon layui-icon-edit"></i></button>
	</script>
	{/block}
{block name="script"}

<script type="text/html" id="user-last_login_time">
    {{layui.util.toDateString(parseInt(d.login_time)*1000, 'yyyy-MM-dd HH:mm')}}
</script>
<script type="text/html" id="user-avatar">
    {{# if(d.avatar){ }}
    <div class="thumb" style="width:30px;height:30px;display:inline-block;"><img src="{{ d.avatar }}" width="30" height="30"></div>
    {{# } else { }}
    <div class="thumb" style="width:30px;height:30px;display:inline-block;"><img src="/static/mp/noavatar.png" width="30" height="30"></div>
    {{#} }}
</script>
<script type="text/html" id="user-brokerage">
    <span>¥{{ d.brokerage}}</span>
</script>
<script>
    layui.use(['table', 'form', 'jquery', 'common', 'laydate'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        let common = layui.common;
        let cols = [
            [{
                type: 'checkbox'
            },
            {
                title: 'ID',
                field: 'id',

            },
            {
                title:"OPENID",
                field:'openid'
            },
            {
                title: '会员昵称',
                field: 'nickname',
             
            },
            {
                title: '注册手机',
                field: 'mobile',
              
            },
            {
                title: '头像',
                field: 'avatar',
                align: 'center',
                templet:'#user-avatar'
            },
            {
                title: '账户余额',
                field: 'balance',
                align: 'center',
            },
            {
                title: '积分',
                field: 'score',
              
            },
            {
                title: '最后登录时间',
                field: 'login_time',
                templet:'#user-last_login_time'
            },
            
            {
                title: '操作',
                toolbar: '#table-bar',
                align: 'center',
                width: 130
            }
            ]
        ]

        table.render({
            elem: '#table-list',
            url: '{:url("index")}',
            parseData: function(res){ 
            return {
            "code": res.code, //解析接口状态
            "msg": res.message, //解析提示文本
            "count": res.data.total, //解析数据长度
            "data": res.data.data //解析数据列表
            }},
            page: true,
            cols: cols,
            skin: 'line',
            toolbar: '#table-toolbar',
            defaultToolbar: [{
                title: '刷新',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter']
        });
        form.on('submit(table-query)', function (data) {
            table.reload('table-list', {
                where: data.field
            })
            return false;
        });
        table.on('tool(table-list)', function (obj) {
            if (obj.event === 'detail') {
                common.modalo('{:url("detail")}?ids=' + obj.data['id'],'编辑','560px');
            }
            if (obj.event === 'edit') {
                common.modalo('{:url("edit")}?ids=' + obj.data['id'],'编辑','560px');
            }
        });      
    })
</script>
{/block}